package com.example.lib_net

import com.blankj.utilcode.util.SPUtils
import okhttp3.OkHttpClient
import okhttp3.logging.HttpLoggingInterceptor
import retrofit2.Retrofit
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory
import retrofit2.converter.gson.GsonConverterFactory
import java.util.concurrent.TimeUnit

class RetrofitUtils {
    companion object{
        fun getRetrofit(): Retrofit {
           val client=OkHttpClient.Builder()
               .writeTimeout(30,TimeUnit.SECONDS)
               .connectTimeout(30,TimeUnit.SECONDS)
               .readTimeout(30,TimeUnit.SECONDS)
               .addInterceptor(HttpLoggingInterceptor().setLevel(HttpLoggingInterceptor.Level.BODY))
               .addInterceptor {
                   val token=SPUtils.getInstance().getString("token")
                   val request=it.request().newBuilder().addHeader("token",token).build()

                   it.proceed(request)
               }.build()
            val retrofit=Retrofit.Builder()
                .client(client)
                .baseUrl("http://10.161.9.80:2209")
                .addConverterFactory(GsonConverterFactory.create())
                //.addCallAdapterFactory(RxJava2CallAdapterFactory.create())
                .build()
            return  retrofit

        }
    }
}